<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <!-- 引入react核心库 -->
  <script src="../js/react.development.js"></script>
  <!-- 引入react-dom,用于支持react操作DOM -->
  <script src="../js/react-dom.development.js"></script>
  <!-- 引入babel,用于将jsx转换为js -->
  <script src="../js/babel.min.js"></script>

  <body>
    <!-- 容器 -->
    <div id="app"></div>
  </body>

  <script type="text/babel">
    class Login extends React.Component {
      handleSubmit = (e) => {
        e.preventDefault();
        const { username, password } = this;
        alert(`你输入的用户名是${username.value},密码是${password.value}`);
      };

      render() {
        return (
          <form action="" onSubmit={this.handleSubmit}>
            <div>
              用户名：{" "}
              <input
                type="text"
                ref={(c) => {
                  this.username = c;
                }}
                name="username"
              />
            </div>
            <div>
              密码：{" "}
              <input
                type="password"
                ref={(c) => {
                  this.password = c;
                }}
                name="password"
              />
            </div>
            <div>
              <button>登录</button>
            </div>
          </form>
        );
      }
    }

    ReactDOM.render(<Login />, document.getElementById("app"));
  </script>
</html>
